<?php

class DataService {

  /**
   * @var DataService
   */
  protected static $_inst;
  protected $_serivces;

  /**
   * @return DataService
   */
  public static function getInst() {
    if (self::$_inst == NULL) {
      self::$_inst = new self();
    }
    return self::$_inst;
  }

  /**
   *
   * @param  int $id
   * @param  string $type
   * @return int
   */
  public static function addObject($id, $type) {
    $db = Db::factory();
    if ($db->insert('object', array('object_id' => $id, 'object_model' => $type))) {
      return $db->lastInsertId();
    }
    return 0;
  }

  /**
   *
   * @param int $oid
   */
  public static function removeObject($oid) {
    $db = Db::factory()->query("delete from object_where oid =  ?", (int) $oid);
  }

  /**
   *
   * @param int $oid
   */
  public static function getObject($oid) {
    
  }

  public static function getService($serivce_name) {
    $inst = self::getInst();
    if (@$inst->_serivces[$service_name] == NULL) {
      $class_name = 'DataService_' . $service_name;
      $inst->_serivces[$service_name] = new $class_name;
    }
    return $inst->_serivces[$service_name];
  }

}